var dataTime = []; //存储七天内的时间
var dataLength = -7;
//获取七天内时间
function fun_date(aa) {
	var date1 = new Date(),
		time1 = date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate(); //time1表示当前时间
	var date2 = new Date(date1);
	date2.setDate(date1.getDate() + aa);
	var time2 = date2.getFullYear() + "-" + (date2.getMonth() + 1) + "-" + date2.getDate();
	return time2;
}

for (var i = dataLength; i < 0; i++) {
	dataTime.push(fun_date(i));
}

function dataHtml(count) {
	// var chartData = JSON.parse('{"amount":[0.03,0,0,0,0,0,0],"number":[1,0,0,0,0,0,0]}');

	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById('transnum'));

	// 指定图表的配置项和数据
	var option = {
		title: {
			text: ''
		},
		tooltip: {
			trigger: 'axis'
		},
		legend: {
			data: dataTime
		},
		grid: {
			left: '3%',
			right: '4%',
			bottom: '3%',
			containLabel: true
		},
		toolbox: {
			show: false,
			feature: {
				saveAsImage: {}
			}
		},
		xAxis: {
			type: 'category',
			boundaryGap: false,
			axisLine: {
				lineStyle: {
					color: '#666'
				}
			},
			data: dataTime
		},
		yAxis: {
			type: 'value',
			axisLine: {
				lineStyle: {
					color: '#666'
				}
			}
		},
		series: [{
			name: '交易笔数',
			type: 'line',
			stack: '总量',
			symbolSize: 8, //拐点圆的大小
			color: ['#3190D2'],
			itemStyle: {
				normal: {
					lineStyle: {
						color: '#3190D2'
					}
				}
			},
			data: count
		}]
	};
	// 使用刚指定的配置项和数据显示图表。
	myChart.setOption(option);
}

function dataHtml2(amount) {
	// 基于准备好的dom，初始化echarts实例
	var myChart = echarts.init(document.getElementById('pricenum'));

	// 指定图表的配置项和数据
	var option = {
		color: ['#3398DB'],
		tooltip: {
			show: true,
			trigger: 'axis',
			axisPointer: { // 坐标轴指示器，坐标轴触发有效
				type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
			}
		},
		grid: {
			left: '3%',
			right: '4%',
			bottom: '3%',
			containLabel: true
		},
		xAxis: [{
			type: 'category',
			data: dataTime,
			axisTick: {
				alignWithLabel: true
			},
			axisLine: {
				lineStyle: {
					color: '#666'
				}
			}
		}],
		yAxis: [{
			type: 'value',
			axisLine: {
				lineStyle: {
					color: '#666'
				}
			}
		}],
		series: [{
			name: '交易总金额',
			type: 'bar',
			barWidth: '60%',
			data: amount
		}]
	};
	// 使用刚指定的配置项和数据显示图表。
	myChart.setOption(option);
}
var vm = avalon.define({
	$id: "home",
	list: [],
	token: localData.get('token'), //获取传过来的token值
	dateshow: false,
	dateshow2: false,
	countlist: [],
	amountlist: [],
})
vm.$watch('onReady', function() {
	console.log(1);
	
	postData(api_gethomepagestat, {
		token: vm.token,
	}, function(res) {
		console.log(res.data[0].week_total_count);
		if (res.status == 'SUCCESS') {
			// console.log(11);
			vm.list = res.data[0];
			vm.dateshow = true;
			vm.dateshow2 = true;
			vm.countlist = res.data[0].week_total_count;
			vm.amountlist = res.data[0].week_total_amount ;
			console.log(vm.countlist);
// 			console.log(vm.countlist);
// 			console.log(22);
// 			console.log(res.data[0].week_total_count);
// 			var count = [];
// 			var amount = [];
// 			if (navigator.userAgent.indexOf("MSIE 8.0")>0){
// 				console.log(1);
// 				for (var key = 0;key < vm.countlist.length;key++) {
// 					count.push(vm.countlist[key] * 1); 			}
// 				for (var key = 0;key < vm.amountlist.length;key++) {
// 					amount.push(vm.countlist[key] * 1);
// 				}
// 			} else {
// 				for (var key in vm.countlist) {
// 					count.push(vm.countlist[key] * 1);
// 				}
// 				for (var key in vm.amountlist) {
// 					amount.push(vm.countlist[key] * 1);
// 				}
//             }
			dataHtml2(vm.countlist);
			dataHtml(vm.amountlist);
// 			console.log(JSON.stringify(count));
// 			console.log(JSON.stringify(amount));
// 			console.log(44);
			
		} else {
			console.log(12);
			alert(res.msg);
		}

	});
})
$(document).ready(function(){
    if (navigator.userAgent.indexOf("MSIE 8.0")>0){
		$('.carvers').addClass('add-carvers');
	} else{
		$('.carvers').removeClass('add-carvers');
	}
})